package com.example.demo.conroller;

import org.json.JSONException;
import org.json.JSONObject;

import com.baidu.aip.speech.AipSpeech;
/**
 * 语音转文字
 * @author Hasee
 *
 */
public class YuYinTOText {
    //设置APPID/AK/SK
    public static final String APP_ID = "15779092";
    public static final String API_KEY = "urIv7uVGWxahHg1hEXiD0y35";
    public static final String SECRET_KEY = "VGYdGtuVLytVNam9QnMfb5SUU7EB1V3b";

    public static void main(String[] args) {
     try {
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(12000);
        client.setSocketTimeoutInMillis(160000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
       // client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
      //  client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");

        // 调用接口
       // JSONObject res = client.asr("C:\\Users\\Hasee\\Downloads\\16k.pcm", "pcm", 16000, null);
      //  JSONObject res = client.asr("C:\\Users\\Hasee\\Downloads\\16k.wav", "wav", 16000, null);
        //  JSONObject res = client.asr("C:\\Users\\Hasee\\Downloads\\aa1.wav", "wav", 16000, null);
       JSONObject res = client.asr("C:\\Users\\Hasee\\Downloads\\16k-23850.amr", "amr", 16000, null);
     
			System.out.println(res.toString(2));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    }
}